package com.example.za407.myapplication;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button star=null;
    private Button stop=null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        star=(Button)findViewById(R.id.button);
        star.setOnClickListener(new starbutton());
        stop=(Button)findViewById(R.id.button2);
        stop.setOnClickListener(new stopbutton());

    }
    Handler handler=new Handler();

    private class starbutton implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            handler.post(runnable);

        }
    }

    private class stopbutton implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            handler.removeCallbacks(runnable);

        }
    }
    Runnable runnable=new Runnable() {
        @Override
        public void run() {
            Toast.makeText(MainActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
            Log.e("tag","runnable");
            handler.postDelayed(runnable,4000);

        }
    };
}
